
import $ from "jquery";
var vscroll = {};
vscroll.init = function () {
    $(function () {
        $(".scroll-wrapper").each(function () {
            var $content = $("<div class='scroll-content'></div>")
            var item = $(this).find(".v-item");
            var w = item.width(),h = item.height();
            item.width(w).height(h);
            var sw = item.length * (w + 10);
            $content.width(sw);
            item.appendTo($content);
            // $(this).find(".scroll-content").width(sw);
            $(this).height(h + 20).addClass("overflow-x").append($content)
        })
    })
}
vscroll.scrollUpDownH = 0;
vscroll.scrollUpDown = function(up,down){
    let that = this;
    $(function () {
        $(window).scroll(function() {
            var sTop = $(document).scrollTop();
            if (sTop - that.scrollUpDownH >= 0) {
              //down
              if(down) down(sTop);
              else up(sTop);
            } else {
                //up
              if(up) up(sTop);
            }
            that.scrollUpDownH = sTop;
          });
    });
}
vscroll.scrollTop = function(){
    return $(document).scrollTop();
}
vscroll.scrollTo = function(n){
    $("html,body").animate({scrollTop:n},0);
}
export default vscroll;